package com.control.servlet;

import com.dao.UserDao;
import com.model.User;
import com.utils.DbUtil;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

/**
 * Created by Administrator on 2017/5/16.
 */
public class LoginServlet extends HttpServlet {

    UserDao userDao = new UserDao();

    public void init() throws ServletException {
        super.init();
    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        List<User> users = userDao.JudgeUsers(req.getParameter("name"),req.getParameter("password"));

       if(users.size()==0){
            String tip="用户名或者密码错误，请重新登录！";
            req.setAttribute("tip", tip);
            RequestDispatcher dispatcher = req.getRequestDispatcher("/jsp/LoginActivity.jsp");
            dispatcher.forward(req, resp);
        }

        else{
            resp.sendRedirect("blogs.do");
        }

    }
}
